/**
 * @param {number[]} nums
 * @param {number[]} queries
 * @return {number[]}
 */
var answerQueries = function (nums, queries) {
  let res = []
  nums.sort((a, b) => a - b)
  for (let i = 0; i < queries.length; i++) {
    let tempSum = 0,
      left = 0,
      tempCount = 0
    while (tempSum < queries[i]) {
      tempCount++
      tempSum+=nums[left]
      left++
    }
    if(tempSum==queries[i]){
      res.push(tempCount)
    }else{
      res.push(tempCount-1)
    }
  }

  return res
}

answerQueries([4,5,2,1],[3,10,21])